//package com.gxd.ssoclient.filter;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.gxd.commons.model.Result;
//import com.gxd.ssoclient.utils.JwtHelper;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * Author: lin.xj
// * Date: 2016-10-25
// * Description:
// */
//@Component
//public class HTTPBearerAuthorizeAttribute extends OncePerRequestFilter {
//
//    @Value("${jwt.base64Security}")
//    private String base64Security;
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
//        Result result;
//        String auth = httpServletRequest.getHeader("Authorization");
//        if ((auth != null) && (auth.length() > 7))
//        {
//            String HeadStr = auth.substring(0, 6).toLowerCase();
//            if (HeadStr.compareTo("bearer") == 0)
//            {
//
//                auth = auth.substring(7, auth.length());
//                if (JwtHelper.parseJWT(auth, base64Security) != null)
//                {
//                    filterChain.doFilter(httpServletRequest, httpServletResponse);
//                    return;
//                }
//            }
//        }
//
//        httpServletResponse.setCharacterEncoding("UTF-8");
//        httpServletResponse.setContentType("application/json; charset=utf-8");
//        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
//
//        ObjectMapper mapper = new ObjectMapper();
//
//        result = new Result(false, -1, "验证失败");
//        httpServletResponse.getWriter().write(mapper.writeValueAsString(result));
//        String authService = this.getFilterConfig().getInitParameter("services.auth");
//        httpServletResponse.sendRedirect(authService + "?redirect=" + httpServletRequest.getRequestURL());
//
//        return;
//    }
//
//    @Override
//    public void destroy() {
//        // TODO Auto-generated method stub
//
//    }
//}
